package Team.Yaohuo.utils;


import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.client.HttpClientErrorException;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @Autowired
    private HttpServletResponse httpServletResponse;

    @ExceptionHandler
    public void loginException(HttpClientErrorException ex) throws IOException {
        log.error("异常信息：{}", ex.getMessage());
        // 未登录跳转
        httpServletResponse.sendRedirect("/notLogin.html");
    }

}
